package com.study.www.demo.web;

import com.alibaba.fastjson.JSONObject;
import com.study.www.demo.Application;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : Administrator.zhuyanpeng
 * @date : 2019/11/15 - 16:52
 */
@Slf4j
@RequestMapping("/demo")
@RestController
public class DemoController {

    public static Map<String,String> map;

    @PostConstruct
    public void init(){
        map = new HashMap<>(2);
        map.put("1","AAA");
        map.put("2","bbb");
    }

    @GetMapping("/{id}")
    public String findById(@PathVariable  String id){
        log.warn("DemoController 的 findById ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
        return map.get(id);
    }

    @PostMapping("")
    public String postById(@RequestBody JSONObject jsonObject){
        return map.put(jsonObject.getString("key"),jsonObject.getString("value"));
    }

}
